

import os

from langchain.chains.question_answering.map_reduce_prompt import messages
from langchain.chains.summarize.map_reduce_prompt import prompt_template
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

os.environ["OPENAI_API_KEY"] = "sk-LWrEtbcCBNIilP3lvzQhVbizLhKUNxCY41hCV5N1yGxck9Ik"
# 1、创建模型
model = ChatOpenAI(
    api_key="sk-CftUbVSsA61lwwgMz9xvt6znTunQZfgBP8ZCVLbQsKfXUR6k",
    model='deepseek-ai/DeepSeek-V3',
    base_url="https://www.henapi.top/v1"
)
messages=[
    SystemMessage(content="把下面翻译成意大利语"),
    HumanMessage(content="hi!"),
]
parser=StrOutputParser()

# 调用示例
#
# response = model.invoke(messages)
# # result=parser.invoke(response)
#
# chain =  model | parser
# result=chain.invoke(messages)
# print(result)

system_template="翻译下面的语句为{language}"
prompt_template=ChatPromptTemplate.from_messages(
    [("system",system_template), ("user", "{text}")]
)
# result=prompt_template.invoke({"language":"英语","text":"你好"})
chain =prompt_template | model | parser
result=chain.invoke({"language":"英语","text":"你好"})
print(result)